#include <blackbox/blackbox.h>
#include <buola/media/audio/baudiotestsrc.h>

#define M_PI_M2 ( M_PI + M_PI )

namespace buola { namespace blackbox {

BAudioTestSrc::BAudioTestSrc()
    :   BBox("audio test source")
    ,   oWave(this,"wave out")
{
    mWaveType=WAVE_SINE;
    mVolume=0.8;
    mFreq=220.0;
    mSampleRate=44100;
    mSamplesPerBuffer=4096;
    mSampleSize=32;

    mNextSample=0;
}

void BAudioTestSrc::CreateBuffer()
{
    CBuffer<int16_t> lBuffer=oWave.NewBuffer(mSamplesPerBuffer);

    lBuffer.SetOffset(mNextSample);

    int16_t *lData=lBuffer.Data();

    for(int i=0;i<mSamplesPerBuffer;i++)
    {
        lData[i]=(int16_t)(20000*sin(M_PI_M2*mNextSample*mFreq/mSampleRate));
        mNextSample++;
    }

    oWave.PushBuffer(lBuffer);
}

/*namespace blackbox*/ } /*namespace buola*/ }
